### Full setup: construct, configure, start GameStateListener Source: https://github.com/antonpup/dota2gsi C# example showing the full setup: construct GameStateListener with port 3000, generate the GSI config file, and start the listener. If config generation fails (e.g., Steam/Dota 2 not installed) or the listener fails to start, a message is printed. ```csharp // Full setup: construct → configure (write cfg) → start GameStateListener gsl = new GameStateListener(3000); if (!gsl.GenerateGSIConfigFile("MyApplication")) { Console.WriteLine("Could not generate GSI config file (is Steam + Dota 2 installed?)."); } if (!gsl.Start()) { Console.WriteLine("Listener failed to start."); } ``` -------------------------------- ### Usage Example Source: https://github.com/antonpup/dota2gsi Example demonstrating how to access wearable items and other game state data from the OnNewGameState callback. ```APIDOC ## Usage Example ### Description Example demonstrating how to access wearable items and other game state data from the OnNewGameState callback. ### Code ```csharp void OnNewGameState(GameState gs) { // Minimap: find a unit foreach (var kvp in gs.Minimap.GetByUnitName("npc_dota_roshan")) { Console.WriteLine($"Roshan on minimap: {kvp.Value.Location}"); } // Roshan if (gs.Roshan.IsValid()) { Console.WriteLine($"Roshan HP: {gs.Roshan.Health}/{gs.Roshan.MaxHealth}"); } // Couriers foreach (var kvp in gs.Couriers.CouriersMap) { Console.WriteLine($"Courier {kvp.Key}: owner {kvp.Value.OwnerID}, alive {kvp.Value.IsAlive}"); } // Neutral items foreach (var teamKvp in gs.NeutralItems.TeamItems) { foreach (var tierKvp in teamKvp.Value.TeamItems) { foreach (var itemKvp in tierKvp.Value) { Console.WriteLine($"[{teamKvp.Key}] {itemKvp.Value.Name} (tier {itemKvp.Value.Tier})"); } } } // Wearables var wearables = gs.Wearables.LocalPlayer.Wearables; foreach (var kvp in wearables) { Console.WriteLine($"Slot {kvp.Key}: item ID {kvp.Value.ID}, style {kvp.Value.Style}"); } // Events foreach (var evt in gs.Events.GetForTeam(PlayerTeam.Radiant)) { Console.WriteLine($"[{evt.GameTime}] {evt.EventType}"); } } ``` ``` -------------------------------- ### Start GameStateListener Source: https://github.com/antonpup/dota2gsi/blob/master/README.md Calls Start() to begin capturing HTTP POST requests. Returns True on success, False on failure (often due to insufficient permissions or port already in use). ```C# if (!gsl.Start()) { // GameStateListener could not start. } // GameStateListener started and is listening for Game State requests. ``` -------------------------------- ### Start Source: https://github.com/antonpup/dota2gsi Starts the HttpListener and spawns a background thread running the accept loop. Returns true if the listener started successfully. ```APIDOC ## Start ### Description Starts the HttpListener and spawns a background thread running the accept loop. Returns true if the listener started successfully. ### Method Start ### Signature ```csharp public bool Start() ``` ### Returns `bool` — `true` if the listener started. `false` if it was already running, or when `HttpListener.Start()` throws `HttpListenerException` (typically the port is already in use, or the process lacks permission for the configured prefix). ``` -------------------------------- ### Example: OnMapState handler Source: https://github.com/antonpup/dota2gsi Example method that checks if the Map node is valid and prints map name, match ID, game state, daytime, paused status, scores, and winning team. ```csharp void OnMapState(GameState gs) { if (!gs.Map.IsValid()) { return; } Console.WriteLine($"Map: {gs.Map.Name}, Match: {gs.Map.MatchID}"); Console.WriteLine($"State: {gs.Map.GameState}, Daytime: {gs.Map.IsDaytime}, Paused: {gs.Map.IsPaused}"); Console.WriteLine($"Score {gs.Map.RadiantScore} - {gs.Map.DireScore}, Winner: {gs.Map.WinningTeam}"); } ``` -------------------------------- ### Basic GameStateListener usage Source: https://github.com/antonpup/dota2gsi Sets up a GameStateListener on port 3000, subscribes to NewGameState, and starts listening. If Start() fails, it prints an error and returns. The handler outputs match ID, clock time, daytime, and local player gold. Stop() and Dispose() are called later. ```csharp using Dota2GSI; GameStateListener gsl = new GameStateListener(3000); // http://localhost:3000/ gsl.NewGameState += OnNewGameState; if (!gsl.Start()) { Console.WriteLine("Could not start listener (port in use?)"); return; } void OnNewGameState(GameState gs) { Console.WriteLine($"Match: {gs.Map.MatchID}, time: {gs.Map.ClockTime}, daytime: {gs.Map.IsDaytime}"); Console.WriteLine($"Local player gold: {gs.Player.LocalPlayer.Gold}"); } // Later: gsl.Stop(); gsl.Dispose(); ``` -------------------------------- ### GameStateListener.Start() Source: https://github.com/antonpup/dota2gsi Starts the listener to begin receiving game state updates. Returns true if the listener started successfully; otherwise, false. ```APIDOC ## Method: Start() ### Description Starts the listener to begin receiving game state updates. Returns `true` if the listener started successfully; otherwise, `false`. ### Returns - `bool` - `true` if the listener started successfully; otherwise, `false`. ### Remarks Common failure reasons include insufficient permissions for a non-localhost prefix, or the port already being bound. ### Example ```csharp if (!gsl.Start()) { Console.WriteLine("Could not start listener (port in use?)"); return; } ``` ``` -------------------------------- ### Generated Game State Integration configuration file Source: https://github.com/antonpup/dota2gsi Example of a fully generated GSI config file written by Dota2GSIFile.CreateFile or GameStateListener.GenerateGSIConfigFile. It sets the server URI, timeout, buffer, throttle, heartbeat, and enables all data sections. The file is written to \game\dota\cfg\gamestate_integration\gamestate_integration_.cfg. ```text "Example Integration Configuration" { "uri" "http://localhost:3000/" "timeout" "5.0" "buffer" "0.1" "throttle" "0.1" "heartbeat" "10.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" } } ``` -------------------------------- ### Handle Start() returning false Source: https://github.com/antonpup/dota2gsi GameStateListener.Start() catches HttpListenerException internally and returns false when the listener cannot start, e.g., due to port in use or permission issues. Check the return value to handle failure. ```csharp if (!gsl.Start()) { Console.WriteLine("Listener could not start (port in use / permissions)."); } ``` -------------------------------- ### Example: accessing items and abilities from GameState Source: https://github.com/antonpup/dota2gsi Shows how to iterate over the local player's inventory, check for a specific item, and access teleport and neutral items. Also demonstrates iterating over abilities to find ready, non-passive ones. ```csharp void OnNewGameState(GameState gs) { var items = gs.Items.LocalPlayer; foreach (var item in items.Inventory) { if (item.Name != "empty") { Console.WriteLine($"Inventory: {item.Name} (charges: {item.Charges})"); } } if (items.InventoryContains("item_blink")) { Console.WriteLine("Has Blink Dagger"); } Console.WriteLine($"TP: {items.Teleport.Name}, Neutral: {items.Neutral.Name}"); // Abilities foreach (var ability in gs.Abilities.LocalPlayer) { if (ability.CanCast && !ability.IsPassive) { Console.WriteLine($"Ready: {ability.Name} (cd {ability.Cooldown}s)"); } } } ``` -------------------------------- ### GameStateListener.Start() Source: https://github.com/antonpup/dota2gsi Starts the GameStateListener. Returns false if already running or if an HttpListenerException is thrown. ```APIDOC ## GameStateListener.Start() ### Description Starts the GameStateListener. Returns false if already running or if an HttpListenerException is thrown. ### Method Start ### Returns - `bool` - `false` if already running or `HttpListenerException` thrown. ### Source `GameStateListener.cs:182` ``` -------------------------------- ### GameState usage example Source: https://github.com/antonpup/dota2gsi Shows how to access various game state data including minimap units, Roshan, couriers, neutral items, wearables, and events. Uses the GameState object passed to OnNewGameState. ```csharp void OnNewGameState(GameState gs) { // Minimap: find a unit foreach (var kvp in gs.Minimap.GetByUnitName("npc_dota_roshan")) { Console.WriteLine($"Roshan on minimap: {kvp.Value.Location}"); } // Roshan if (gs.Roshan.IsValid()) { Console.WriteLine($"Roshan HP: {gs.Roshan.Health}/{gs.Roshan.MaxHealth}"); } // Couriers foreach (var kvp in gs.Couriers.CouriersMap) { Console.WriteLine($"Courier {kvp.Key}: owner {kvp.Value.OwnerID}, alive {kvp.Value.IsAlive}"); } // Neutral items foreach (var teamKvp in gs.NeutralItems.TeamItems) { foreach (var tierKvp in teamKvp.Value.TeamItems) { foreach (var itemKvp in tierKvp.Value) { Console.WriteLine($"[{teamKvp.Key}] {itemKvp.Value.Name} (tier {itemKvp.Value.Tier})"); } } } // Wearables var wearables = gs.Wearables.LocalPlayer.Wearables; foreach (var kvp in wearables) { Console.WriteLine($"Slot {kvp.Key}: item ID {kvp.Value.ID}, style {kvp.Value.Style}"); } // Events foreach (var evt in gs.Events.GetForTeam(PlayerTeam.Radiant)) { Console.WriteLine($"[{evt.GameTime}] {evt.EventType}"); } } ``` -------------------------------- ### CreateFile (string overload) signature Source: https://github.com/antonpup/dota2gsi Public static method at Dota2GSIFile.cs:33. Takes an integration name and a URI for the game to POST to. Returns true on success, false on failure (e.g., Steam install not found, path creation/write error). ```csharp public static bool CreateFile(string name, string uri) ``` -------------------------------- ### Example: Accessing player details and team players Source: https://github.com/antonpup/dota2gsi Shows how to access local player stats, iterate team players, and use lookup helpers like GetForTeam and GetForPlayer. Requires a valid GameState object. ```csharp void OnNewGameState(GameState gs) { var local = gs.Player.LocalPlayer; if (local.IsValid()) { Console.WriteLine($"{local.Name}: {local.Kills}/{local.Deaths}/{local.Assists} KDA, {local.Gold} gold"); } // Spectating: iterate team players foreach (var teamKvp in gs.Player.Teams) { foreach (var playerKvp in teamKvp.Value) { Console.WriteLine($"[{teamKvp.Key}] player {playerKvp.Key}: {playerKvp.Value.Name}"); } } // Lookup helpers var radiantPlayers = gs.Player.GetForTeam(PlayerTeam.Radiant); var p = gs.Player.GetForPlayer(2); } ``` -------------------------------- ### SteamUtils.GetGamePath Source: https://github.com/antonpup/dota2gsi Returns the install directory of the given Steam AppID, or null when not found. The method resolves the Steam install path from the registry, reads libraryfolders.vdf, and locates the appmanifest file to determine the installation directory. ```APIDOC ## SteamUtils.GetGamePath ### Description Returns the install directory of the given Steam AppID, or null when not found. The method resolves the Steam install path from the registry, reads libraryfolders.vdf, and locates the appmanifest file to determine the installation directory. ### Method GetGamePath ### Signature ```csharp public static string GetGamePath(int game_id) ``` ### Parameters #### game_id (int) - Required Steam AppID of the game. ### Returns - **string** - The install directory of the given AppID, or null when not found. ``` -------------------------------- ### Example usage of Hero and TalentTreeSpec Source: https://github.com/antonpup/dota2gsi Shows how to access the local player's hero details and check the talent tree selection. Uses hero.IsValid() to guard against invalid hero data, and prints health, mana, alive status, respawn time, and buyback cost. ```csharp void OnNewGameState(GameState gs) { var hero = gs.Hero.LocalPlayer; if (!hero.IsValid()) { return; } Console.WriteLine($"{hero.Name} (lvl {hero.Level}): {hero.Health}/{hero.MaxHealth} HP, {hero.Mana}/{hero.MaxMana} MP"); Console.WriteLine($"Alive: {hero.IsAlive}, respawn in {hero.SecondsToRespawn}s, buyback ${hero.BuybackCost}"); if (hero.TalentTree[3] == TalentTreeSpec.Left) { Console.WriteLine("Level 25 left talent chosen"); } } ``` -------------------------------- ### Check for null path and config file generation failure Source: https://github.com/antonpup/dota2gsi Use this to verify that the Steam/Dota 2 install path is found and that the GSI config file was written successfully. The path is null when the game is not installed or the platform is unsupported; GenerateGSIConfigFile returns false if file creation fails. ```csharp string path = SteamUtils.GetGamePath(570); if (path == null) { Console.WriteLine("Steam/Dota 2 install not found on this machine."); } if (!gsl.GenerateGSIConfigFile("MyApp")) { Console.WriteLine("Could not write the GSI config file."); } ``` -------------------------------- ### Generated GSI configuration file content Source: https://github.com/antonpup/dota2gsi/blob/master/README.md The resulting configuration file content after calling GenerateGSIConfigFile("Example"). It specifies the URI, timeout, buffer, throttle, heartbeat, and enables all data sections. ```text "Example Integration Configuration" { "uri" "http://localhost:3000/" "timeout" "5.0" "buffer" "0.1" "throttle" "0.1" "heartbeat" "10.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" } } ``` -------------------------------- ### Example: NodeMap / NodeList Source: https://github.com/antonpup/dota2gsi Shows usage of NodeMap and NodeList. NodeMap supports index initializers and ContainsKey; NodeList can be populated via AddRange. Outputs [0: blink] and the ability count. ```csharp using Dota2GSI.Nodes; NodeMap items = new NodeMap { [0] = "blink" }; if (items.ContainsKey(0)) { Console.WriteLine(items.ToString()); // [0: blink] } NodeList abilities = new NodeList(); abilities.AddRange(gs.Abilities.LocalPlayer); Console.WriteLine($"Abilities: {abilities.Count}"); ``` -------------------------------- ### Create integration config and parse ACF/vdf files Source: https://github.com/antonpup/dota2gsi Shows direct file generation without a listener, Steam folder discovery, and parsing an ACF/vdf file. Requires Steam with Dota 2 installed for file creation; otherwise prints a failure message. ```csharp using Dota2GSI; using Dota2GSI.Utils; // Direct file generation without a listener: if (Dota2GSIFile.CreateFile("MyApp", 3000)) { Console.WriteLine("Generated http://localhost:3000/ integration config."); } else { Console.WriteLine("Failed — is Steam with Dota 2 installed?"); } // Steam folder discovery: string dotaPath = SteamUtils.GetGamePath(570); Console.WriteLine(dotaPath ?? "Dota 2 not found"); // Parse an ACF/vdf file: ACF vdf = new ACF(@"C:\Program Files (x86)\Steam\SteamApps\libraryfolders.vdf"); var folders = vdf.Children["libraryfolders"]; foreach (var kvp in folders.Children) { Console.WriteLine(kvp.Value.Items["path"]); } ``` -------------------------------- ### SteamUtils.GetGamePath(game_id) Source: https://github.com/antonpup/dota2gsi Retrieves the installation path of a Steam game. Returns null on non-Windows platforms, missing registry keys, or missing files. ```APIDOC ## SteamUtils.GetGamePath(game_id) ### Description Retrieves the installation path of a Steam game. Returns null on non-Windows platforms, missing registry keys, or missing files. ### Method GetGamePath ### Parameters - `game_id` (int) - Required - The Steam App ID of the game. ### Returns - `string` - The installation path, or `null` if not found. ### Source `SteamUtils.cs:270` ### Example ```csharp string path = SteamUtils.GetGamePath(570); if (path == null) { Console.WriteLine("Steam/Dota 2 install not found on this machine."); } ``` ``` -------------------------------- ### Example: Accessing radiant buildings Source: https://github.com/antonpup/dota2gsi Shows how to access radiant top towers and ancient health from a GameState object. ```csharp void OnNewGameState(GameState gs) { BuildingLayout radiant = gs.Buildings.RadiantBuildings; foreach (var kvp in radiant.TopTowers) { Building tower = kvp.Value; Console.WriteLine($"Radiant top tower {kvp.Key}: {tower.Health}/{tower.MaxHealth}"); } if (radiant.Ancient.Health == 0) { Console.WriteLine("Radiant ancient is destroyed!"); } } ``` -------------------------------- ### Example usage of League and Draft nodes Source: https://github.com/antonpup/dota2gsi Shows how to access league and draft information from a GameState object. Checks if the league and draft are valid before reading properties. Outputs league name, tier, series type, team tags, prize pool, active team, pick, and team pick IDs. ```csharp void OnNewGameState(GameState gs) { if (gs.League.IsValid()) { Console.WriteLine($"{gs.League.Name} (tier {gs.League.Tier})"); Console.WriteLine($"Series: {gs.League.SeriesType}, {gs.League.RadiantTeam.TeamTag} vs {gs.League.DireTeam.TeamTag}"); Console.WriteLine($"Prize pool: {gs.League.TotalPrizePool}"); } if (gs.Draft.IsValid()) { Console.WriteLine($"Active team: {gs.Draft.ActiveTeam}, picking: {gs.Draft.Pick}"); foreach (var kvp in gs.Draft.Teams) { Console.WriteLine($"[{kvp.Key}] picks: {string.Join(", ", kvp.Value.PickIDs.Values)}"); } } } ``` -------------------------------- ### GameStateListener with error handling and custom URI Source: https://github.com/antonpup/dota2gsi Creates a GameStateListener with a custom URI, catching ArgumentException for invalid URIs. Generates a GSI config file for 'MyIntegration' and subscribes to GameEvent. If Start() fails, it prints a message suggesting administrator privileges. The handler prints the game event type name. ```csharp using System; using Dota2GSI; GameStateListener gsl; try { gsl = new GameStateListener("http://127.0.0.1:1234/"); } catch (ArgumentException ex) { Console.WriteLine($"Invalid URI: {ex.Message}"); return; } if (!gsl.GenerateGSIConfigFile("MyIntegration")) { Console.WriteLine("Could not generate GSI config file (Steam not found?)."); } gsl.GameEvent += OnGameEvent; if (!gsl.Start()) { // Commonly: insufficient permissions for a non-localhost prefix, or port already bound. Console.WriteLine("Listener failed to start; try running as administrator."); return; } void OnGameEvent(DotaGameEvent gameEvent) { Console.WriteLine($"Game event: {gameEvent.GetType().Name}"); } ``` -------------------------------- ### Catch ArgumentException for invalid listener URI Source: https://github.com/antonpup/dota2gsi GameStateListener constructor throws System.ArgumentException when the URI does not match the required regex. The example shows a URI without a scheme, which fails validation. ```csharp try { GameStateListener gsl = new GameStateListener("localhost:3000"); // no scheme } catch (ArgumentException ex) { Console.WriteLine(ex.Message); // "Not a valid URI: localhost:3000/" } ``` -------------------------------- ### Pattern-matching on event payloads Source: https://github.com/antonpup/dota2gsi Use this C# example to handle DotaGameEvent payloads by pattern matching on their concrete types. It covers TimeOfDayChanged, TeamScoreChanged, and PlayerGameplayEvent, with a default case for other events. The payloads are produced by StateHandlers, not dispatched by your code. ```csharp using Dota2GSI.EventMessages; void OnGameEvent(DotaGameEvent e) { switch (e) { case TimeOfDayChanged tod: Console.WriteLine($"Daytime: {tod.IsDaytime}, Nightstalker night: {tod.IsNightstalkerNight}"); break; case TeamScoreChanged score: Console.WriteLine($"Score for {score.Team}: {score.New}"); break; case PlayerGameplayEvent pge: Console.WriteLine($"Player {pge.Player.Details.Name}: {pge.Value.EventType}"); break; default: Console.WriteLine($"Event: {e.GetType().Name}"); break; } } ``` -------------------------------- ### Check GameState validity before use Source: https://github.com/antonpup/dota2gsi Use this C# example to verify that a section (e.g., Map) was actually read from the JSON payload before accessing its properties. The IsValid() method on a node reports whether any value was read; if false, the section was not part of the payload. ```csharp void OnNewGameState(GameState gs) { // Node.IsValid() reports whether any value was actually read from JSON. if (!gs.Map.IsValid()) { Console.WriteLine("Map section was not part of this payload."); return; } Console.WriteLine($"Match {gs.Map.MatchID}: {gs.Map.GameState}, paused: {gs.Map.IsPaused}"); } ``` -------------------------------- ### Building.MaxHealth Source: https://github.com/antonpup/dota2gsi Gets the maximum health of a building. ```APIDOC ## Building.MaxHealth ### Description Gets the maximum health of a building. ### Property MaxHealth ### Returns - **int** - The maximum health. ``` -------------------------------- ### Building.Health Source: https://github.com/antonpup/dota2gsi Gets the current health of a building. ```APIDOC ## Building.Health ### Description Gets the current health of a building. ### Property Health ### Returns - **int** - The current health. ``` -------------------------------- ### Create GameStateListener with custom URI Source: https://github.com/antonpup/dota2gsi/blob/master/README.md Instantiates GameStateListener with a custom URI. If the URI is not http://localhost:*/ (e.g., http://192.168.0.2:100/), the application must run with administrator privileges. ```C# GameStateListener gsl = new GameStateListener("http://127.0.0.1:1234/"); ``` -------------------------------- ### Create GameStateListener with port 3000 Source: https://github.com/antonpup/dota2gsi/blob/master/README.md Instantiates GameStateListener on port 3000, making it listen on http://localhost:3000/. Use this when you want to use the default localhost URI with a custom port. ```C# GameStateListener gsl = new GameStateListener(3000); //http://localhost:3000/ ``` -------------------------------- ### Generate GSI configuration file Source: https://github.com/antonpup/dota2gsi/blob/master/README.md Calls GenerateGSIConfigFile to automatically locate the game directory and create the gamestate_integration_.cfg file. Returns True on success, False on failure. The function uses the URI/port from the GameStateListener instance. ```C# if (!gsl.GenerateGSIConfigFile("Example")) { Console.WriteLine("Could not generate GSI configuration file."); } ``` -------------------------------- ### CreateFile (int overload) signature Source: https://github.com/antonpup/dota2gsi Public static method at Dota2GSIFile.cs:20. Takes an integration name and a port; the generated URI is http://localhost:{port}/. Delegates to the string overload. ```csharp public static bool CreateFile(string name, int port) ``` -------------------------------- ### BuildingLayout.OtherBuildings Source: https://github.com/antonpup/dota2gsi Gets any other buildings that do not match the predefined patterns. These are keyed by the property name. ```APIDOC ## BuildingLayout.OtherBuildings ### Description Gets any other buildings that do not match the predefined patterns. These are keyed by the property name. ### Property OtherBuildings ### Returns - **NodeMap** - A map of property names to Building objects. ``` -------------------------------- ### BuildingLayout.BottomTowers Source: https://github.com/antonpup/dota2gsi Gets the bottom lane towers for a building layout. The towers are keyed by tower number. ```APIDOC ## BuildingLayout.BottomTowers ### Description Gets the bottom lane towers for a building layout. The towers are keyed by tower number. ### Property BottomTowers ### Returns - **NodeMap** - A map of tower numbers to Building objects. ``` -------------------------------- ### BuildingLayout.MiddleTowers Source: https://github.com/antonpup/dota2gsi Gets the middle lane towers for a building layout. The towers are keyed by tower number. ```APIDOC ## BuildingLayout.MiddleTowers ### Description Gets the middle lane towers for a building layout. The towers are keyed by tower number. ### Property MiddleTowers ### Returns - **NodeMap** - A map of tower numbers to Building objects. ``` -------------------------------- ### BuildingLayout.TopTowers Source: https://github.com/antonpup/dota2gsi Gets the top lane towers for a building layout. The towers are keyed by tower number. ```APIDOC ## BuildingLayout.TopTowers ### Description Gets the top lane towers for a building layout. The towers are keyed by tower number. ### Property TopTowers ### Returns - **NodeMap** - A map of tower numbers to Building objects. ``` -------------------------------- ### Buildings.DireBuildings Source: https://github.com/antonpup/dota2gsi Gets the building layout for the Dire team. This is a property that returns the layout from the AllBuildings map. ```APIDOC ## Buildings.DireBuildings ### Description Gets the building layout for the Dire team. This is a property that returns the layout from the AllBuildings map. ### Property DireBuildings ### Returns - **BuildingLayout** - The building layout for the Dire team. ``` -------------------------------- ### Buildings.RadiantBuildings Source: https://github.com/antonpup/dota2gsi Gets the building layout for the Radiant team. This is a property that returns the layout from the AllBuildings map. ```APIDOC ## Buildings.RadiantBuildings ### Description Gets the building layout for the Radiant team. This is a property that returns the layout from the AllBuildings map. ### Property RadiantBuildings ### Returns - **BuildingLayout** - The building layout for the Radiant team. ``` -------------------------------- ### FullPlayerDetails constructors Source: https://github.com/antonpup/dota2gsi Two internal constructors: one taking a player ID and game state, the other taking only game state for the local player (PlayerID = -1). The per-player constructor resolves sections via GetForPlayer accessors; the local-player constructor reads LocalPlayer nodes directly and leaves Courier defaulted. ```csharp internal FullPlayerDetails(int player_id, GameState game_state) // FullPlayerDetails.cs:71 ``` ```csharp internal FullPlayerDetails(GameState game_state) // FullPlayerDetails.cs:88 — PlayerID = -1 (local player) ``` -------------------------------- ### BuildingLayout.Ancient Source: https://github.com/antonpup/dota2gsi Gets the ancient building for a building layout. The ancient is matched by the '_fort' suffix in the property name. ```APIDOC ## BuildingLayout.Ancient ### Description Gets the ancient building for a building layout. The ancient is matched by the '_fort' suffix in the property name. ### Property Ancient ### Returns - **Building** - The ancient building. ``` -------------------------------- ### BuildingLayout.BottomRacks Source: https://github.com/antonpup/dota2gsi Gets the bottom lane racks for a building layout. The racks are keyed by RacksType (Melee or Range). ```APIDOC ## BuildingLayout.BottomRacks ### Description Gets the bottom lane racks for a building layout. The racks are keyed by RacksType (Melee or Range). ### Property BottomRacks ### Returns - **NodeMap** - A map of RacksType to Building objects. ``` -------------------------------- ### Dota2GSIFile.CreateFile (string overload) Source: https://github.com/antonpup/dota2gsi Static helper that writes a gamestate_integration_.cfg into the Dota 2 game directory using a custom URI. It creates the necessary directory and ACF document. ```APIDOC ## [STATIC] Dota2GSIFile.CreateFile(string name, string uri) ### Description Static helper that writes a `gamestate_integration_.cfg` into the Dota 2 game directory using a custom URI. It creates the necessary directory and ACF document. ### Method Static method ### Endpoint `Dota2GSIFile.CreateFile(string name, string uri)` ### Parameters - `name` (string) - Required - Integration name. - `uri` (string) - Required - The URI the game should POST to. ### Response #### Success Response - Returns `bool` - `true` on success, `false` on failure (Steam install not found, path creation/write error). ``` -------------------------------- ### BuildingLayout.MiddleRacks Source: https://github.com/antonpup/dota2gsi Gets the middle lane racks for a building layout. The racks are keyed by RacksType (Melee or Range). ```APIDOC ## BuildingLayout.MiddleRacks ### Description Gets the middle lane racks for a building layout. The racks are keyed by RacksType (Melee or Range). ### Property MiddleRacks ### Returns - **NodeMap** - A map of RacksType to Building objects. ``` -------------------------------- ### Dota2GSIFile.CreateFile (int overload) Source: https://github.com/antonpup/dota2gsi Static helper that writes a gamestate_integration_.cfg into the Dota 2 game directory using a port number. It delegates to the string overload. ```APIDOC ## [STATIC] Dota2GSIFile.CreateFile(string name, int port) ### Description Static helper that writes a `gamestate_integration_.cfg` into the Dota 2 game directory using a port number. It delegates to the string overload. ### Method Static method ### Endpoint `Dota2GSIFile.CreateFile(string name, int port)` ### Parameters - `name` (string) - Required - Integration name; the file becomes `gamestate_integration_{name}.cfg`. - `port` (int) - Required - Port; the generated `uri` is `http://localhost:{port}/`. ### Response #### Success Response - Returns `bool` - `true` on success, `false` on failure. ``` -------------------------------- ### BuildingLayout.TopRacks Source: https://github.com/antonpup/dota2gsi Gets the top lane racks for a building layout. The racks are keyed by RacksType (Melee or Range). ```APIDOC ## BuildingLayout.TopRacks ### Description Gets the top lane racks for a building layout. The racks are keyed by RacksType (Melee or Range). ### Property TopRacks ### Returns - **NodeMap** - A map of RacksType to Building objects. ``` -------------------------------- ### FullTeamDetails internal constructor Source: https://github.com/antonpup/dota2gsi Internal constructor for FullTeamDetails that initializes all members from a GameState object. It builds Players from game_state.Player.GetForTeam(team) and assigns Draft, NeutralItems, Buildings, MinimapElements, and Events from corresponding GetForTeam methods. ```csharp internal FullTeamDetails(PlayerTeam team, GameState game_state) // FullTeamDetails.cs:69 ``` -------------------------------- ### Consuming events with helpers Source: https://github.com/antonpup/dota2gsi Shows how to subscribe to game events and access player/team details using Dota2GSI helpers. FullPlayerDetailsUpdated provides player info without extra lookups, while GameState exposes team-level data. ```csharp using Dota2GSI; using Dota2GSI.EventMessages; // FullPlayerDetailsUpdated requires no extra lookups: gsl.GameEvent += OnGameEvent; void OnGameEvent(DotaGameEvent e) { if (e is FullPlayerDetailsUpdated update) { Console.WriteLine($"Player {update.New.PlayerID} ({(update.New.IsLocalPlayer ? "local" : "remote")})"); Console.WriteLine($" Hero: {update.New.Hero.Name}, Level {update.New.Hero.Level}"); Console.WriteLine($" Gold: {update.New.Details.Gold}, Items: {update.New.Items.CountInventory}"); } } // Team-level view from any game state: void ShowTeam(GameState gs) { foreach (var kvp in gs.RadiantTeamDetails.Players) { Console.WriteLine($"[Radiant] {kvp.Value.Details.Name} — {kvp.Value.Hero.Name}"); } Console.WriteLine($"Radiant winner: {gs.RadiantTeamDetails.IsWinner}"); } ``` -------------------------------- ### Minimap query methods Source: https://github.com/antonpup/dota2gsi Methods to retrieve minimap elements: GetForTeam filters by team, GetByUnitName matches UnitName exactly and returns empty for null/empty input. ```csharp public NodeMap GetForTeam(PlayerTeam team) // Minimap.cs:39 public NodeMap GetByUnitName(string unit_name) // Minimap.cs:60 — exact match on UnitName, empty result for null/empty input ``` -------------------------------- ### Abilities methods Source: https://github.com/antonpup/dota2gsi Methods to retrieve ability details by team or player. GetForTeam returns an empty Dictionary when the team is absent. ```csharp public Dictionary GetForTeam(PlayerTeam team) // Abilities.cs:70 — note: returns Dictionary, not NodeMap ``` ```csharp public AbilityDetails GetForPlayer(int player_id) // Abilities.cs:84 ``` -------------------------------- ### GameStateListener Constructor (string uri) Source: https://github.com/antonpup/dota2gsi Initializes a new GameStateListener instance that listens on the specified URI. The URI must be a valid HTTP URI; otherwise, an ArgumentException is thrown. ```APIDOC ## Constructor: GameStateListener(string uri) ### Description Initializes a new GameStateListener instance that listens on the specified URI. The URI must be a valid HTTP URI; otherwise, an `ArgumentException` is thrown. ### Parameters - `uri` (string) - Required - The URI to listen on (e.g., `http://127.0.0.1:1234/`). ### Exceptions - `ArgumentException` - Thrown when the URI is invalid. ### Example ```csharp try { gsl = new GameStateListener("http://127.0.0.1:1234/"); } catch (ArgumentException ex) { Console.WriteLine($"Invalid URI: {ex.Message}"); return; } ``` ``` -------------------------------- ### GameStateListener(int port) constructor Source: https://github.com/antonpup/dota2gsi Builds the listen URI http://localhost:{port}/ and registers it as an HttpListener prefix. The default private constructor subscribes OnNewGameEvent to the internal static EventDispatcher. ```csharp public GameStateListener(int port) : this() ``` -------------------------------- ### GenerateGSIConfigFile Source: https://github.com/antonpup/dota2gsi Generates a Dota 2 GSI configuration file for the listener. The generated configuration targets the listener's own URI and port. ```APIDOC ## GenerateGSIConfigFile ### Description Generates a Dota 2 GSI configuration file for the listener. The generated configuration targets the listener's own URI and port. ### Method GenerateGSIConfigFile ### Signature ```csharp public bool GenerateGSIConfigFile(string name) ``` ### Parameters - `name` (string) - Required - The custom integration name; becomes `gamestate_integration_{name}.cfg`. ### Returns `bool` — `true` when the config file was written, `false` otherwise (e.g. Steam install not found, or file write failed). ``` -------------------------------- ### GetForTeam method Source: https://github.com/antonpup/dota2gsi Returns the hero map for a given team, or an empty NodeMap if not found. ```csharp public NodeMap GetForTeam(PlayerTeam team) ``` -------------------------------- ### GetForTeam method signature Source: https://github.com/antonpup/dota2gsi Returns the building layout for the specified team; returns a new empty BuildingLayout for other teams. ```csharp public BuildingLayout GetForTeam(PlayerTeam team) ``` -------------------------------- ### GameStateListener Constructor (int port) Source: https://github.com/antonpup/dota2gsi Initializes a new GameStateListener instance that listens on the specified port on localhost. The listener will bind to http://localhost:/. ```APIDOC ## Constructor: GameStateListener(int port) ### Description Initializes a new GameStateListener instance that listens on the specified port on localhost. The listener will bind to `http://localhost:/`. ### Parameters - `port` (int) - Required - The port number to listen on. ### Example ```csharp GameStateListener gsl = new GameStateListener(3000); // http://localhost:3000/ ``` ``` -------------------------------- ### GameStateListener(string URI) constructor Source: https://github.com/antonpup/dota2gsi Listens on the given URI, appending a trailing slash if missing. Validates against regex ^https?:\/\/.+:([0-9]*)\/$ and throws ArgumentException on failure. Non-localhost URIs require administrator privileges. ```csharp public GameStateListener(string URI) : this() ``` -------------------------------- ### GameStateListener(int port) Source: https://github.com/antonpup/dota2gsi Initializes a new instance of the GameStateListener class that listens on the specified TCP port. It builds the listen URI as http://localhost:{port}/ and registers it as an HttpListener prefix. ```APIDOC ## GameStateListener(int port) ### Description Initializes a new instance of the GameStateListener class that listens on the specified TCP port. It builds the listen URI as http://localhost:{port}/ and registers it as an HttpListener prefix. ### Method Constructor ### Parameters #### Parameters - **port** (int) - Required - The TCP port to listen on. ### Remarks The default (private) constructor subscribes OnNewGameEvent (the Dota2EventsInterface router) to the internal static EventDispatcher. ``` -------------------------------- ### ACF Constructor Source: https://github.com/antonpup/dota2gsi Initializes a new instance of the ACF class. The parameterless constructor creates an empty ACF object, while the filename constructor parses an existing ACF file if it exists. ```APIDOC ## ACF Constructor ### Description Initializes a new instance of the ACF class. The parameterless constructor creates an empty ACF object, while the filename constructor parses an existing ACF file if it exists. ### Method Constructor ### Signature ```csharp public ACF() public ACF(string filename) ``` ### Parameters #### filename (string) - Optional Path to the ACF file to parse. If the file does not exist, the object is created empty. ``` -------------------------------- ### Pre-processing events with EventDispatcher Source: https://github.com/antonpup/dota2gsi Shows how to use RegisterPreProcessor to swallow HeroDied broadcasts by returning null, preventing delivery to subscribers. The library's dispatcher is private, so this pattern applies when extending the library or building your own handler. ```csharp // Play with the dispatcher directly (the library's dispatcher is private, so this // pattern applies when extending the library or building your own handler). EventDispatcher dispatcher = new EventDispatcher(); dispatcher.RegisterPreProcessor(evt => { Console.WriteLine("Swallowing HeroDied broadcasts"); return null; // stops delivery }); dispatcher.Subscribe(evt => Console.WriteLine("Not reached")); dispatcher.Broadcast(new HeroDied(0, 100, playerDetails)); ``` -------------------------------- ### Enums: DOTA_GameState, PlayerTeam, RoshanState Source: https://github.com/antonpup/dota2gsi Enumerations used across the library for game state, player team, and Roshan state values. ```APIDOC ## Enums ### DOTA_GameState ```csharp public enum DOTA_GameState { Undefined, DOTA_GAMERULES_STATE_DISCONNECT, DOTA_GAMERULES_STATE_GAME_IN_PROGRESS, DOTA_GAMERULES_STATE_HERO_SELECTION, DOTA_GAMERULES_STATE_INIT, DOTA_GAMERULES_STATE_LAST, DOTA_GAMERULES_STATE_POST_GAME, DOTA_GAMERULES_STATE_PRE_GAME, DOTA_GAMERULES_STATE_STRATEGY_TIME, DOTA_GAMERULES_STATE_WAIT_FOR_PLAYERS_TO_LOAD, DOTA_GAMERULES_STATE_CUSTOM_GAME_SETUP, DOTA_GAMERULES_STATE_WAIT_FOR_MAP_TO_LOAD, DOTA_GAMERULES_STATE_TEAM_SHOWCASE } ``` ### PlayerTeam ```csharp public enum PlayerTeam { Unknown = -2, Undefined = -1, None = 0, Spectator = 1, Radiant = 2, Dire = 3, Neutrals = 4 } ``` ### RoshanState ```csharp public enum RoshanState { Undefined = -1, Alive, Respawn_Base, Respawn_Variable } ``` > Enum parsing is performed case-insensitively by `Node.ToEnum` and falls back to `Undefined` on mismatch. ``` -------------------------------- ### NewGameStateHandler delegate Source: https://github.com/antonpup/dota2gsi Handles a newly received game state. Defined at Dota2GSI/GameStateListener.cs:15. ```csharp public delegate void NewGameStateHandler(GameState gamestate); ``` -------------------------------- ### Dota2GSIFile.CreateFile(name, port/uri) Source: https://github.com/antonpup/dota2gsi Creates a GSI config file. Returns false if the Steam game path is not found or if any directory/file creation exception occurs. ```APIDOC ## Dota2GSIFile.CreateFile(name, port/uri) ### Description Creates a GSI config file. Returns false if the Steam game path is not found or if any directory/file creation exception occurs. ### Method CreateFile ### Parameters - `name` (string) - Required - The name of the config file. - `port/uri` (string) - Required - The port or URI to use. ### Returns - `bool` - `false` if Steam game path not found or any `Directory.CreateDirectory`/`File.WriteAllText` exception. ### Source `Dota2GSIFile.cs:20,33` ``` -------------------------------- ### GameStateListener.GenerateGSIConfigFile(name) Source: https://github.com/antonpup/dota2gsi Generates a GSI config file with the given name. Returns false if Dota2GSIFile.CreateFile fails. ```APIDOC ## GameStateListener.GenerateGSIConfigFile(name) ### Description Generates a GSI config file with the given name. Returns false if Dota2GSIFile.CreateFile fails. ### Method GenerateGSIConfigFile ### Parameters - `name` (string) - Required - The name of the config file. ### Returns - `bool` - `false` if `Dota2GSIFile.CreateFile` failed. ### Source `GameStateListener.cs:174` ``` -------------------------------- ### Minimap.GetForTeam(PlayerTeam team) Source: https://github.com/antonpup/dota2gsi Returns a map of minimap elements for a specific team. The method filters the minimap elements by the given team and returns a NodeMap keyed by element ID. ```APIDOC ## Minimap.GetForTeam(PlayerTeam team) ### Description Returns a map of minimap elements for a specific team. The method filters the minimap elements by the given team and returns a NodeMap keyed by element ID. ### Method GetForTeam ### Parameters - **team** (PlayerTeam) - Required - The team to filter minimap elements by. ### Response Returns a `NodeMap` containing minimap elements for the specified team. ``` -------------------------------- ### NodeMap constructors Source: https://github.com/antonpup/dota2gsi Provides an empty constructor and one that populates from an existing dictionary. ToString renders [key: value, ...]. ```csharp public NodeMap() ``` ```csharp public NodeMap(Dictionary dictionary) ``` -------------------------------- ### Dota2GSIFile class declaration Source: https://github.com/antonpup/dota2gsi Public class in the Dota2GSI namespace, defined in Dota2GSI/Dota2GSIFile.cs at line 10. It is a static helper that writes a gamestate_integration_.cfg into the Dota 2 game directory. ```csharp public class Dota2GSIFile ``` -------------------------------- ### GameEventHandler delegate and GameEvent event Source: https://github.com/antonpup/dota2gsi Defines the GameEventHandler delegate and the GameEvent event. The event is initialized with an empty delegate to avoid null checks. The constructor subscribes GameEvent to the dispatcher so all broadcasts also reach GameEvent subscribers. ```csharp public delegate void GameEventHandler(T game_event); public event GameEventHandler GameEvent = delegate { }; ```