This is a JVM library that aims to make working with Dota 2's Game State Integration simple. Game State Integration (GSI) is a feature built into Dota 2 that allows us to ask Dota to periodically send us information on the current game state. You can find more information on Valve's Developer Wiki for CS:GO (the same applies to Dota 2).
In the simplest terms, the library starts up a local server which listens for game state information from the Dota 2 client. It then deserializes this JSON data into type-safe objects for developers to work with.
Why use a library for this? The JSON data that Dota sends can vary significantly in structure, which makes simple parsing very tricky. Specifically, the structure is different when the Dota client is playing a match compared to when it is spectating a match. This library aims to remove this worry from the developer, and simply exposes type-safe objects to work with.
- Set up your Dota 2 client to send game state information to your program.
- Add the dependency to your project.
fun main() {
// Create a server which listens on the port configured during Dota setup:
GameStateServer(44444)
// Register one or more listeners:
.setPlayingListener { gameState ->
// Do something with the received gameState object:
val clockTime = gameState.map?.clockTime
println("The clock time is $clockTime seconds.")
}
// Start the server, blocking the thread so the program doesn't immediately exit:
.start() // Alternatively startAsync() will not block the thread.
}
public class GsiDemo {
public static void main(String[] args) {
// Create a server which listens on the port configured during Dota setup:
GameStateServer.create(44444)
// Register one or more listeners:
.setPlayingListener(gameState -> {
// Do something with the received gameState object:
if (gameState.getMap() != null) {
int clockTime = gameState.getMap().getClockTime();
System.out.println("The clock time is " + clockTime + " seconds.");
}
})
// Start the server, blocking the thread so the program doesn't immediately exit:
.start(); // Alternatively startAsync() will not block the thread.
}
}
- The project's Wiki.
- The full API reference.
- The demo project has some more involved examples.
The library requires at least Java 8 to compile.
Additionally, the library depends on a few third party dependencies. If you use older versions of these dependencies in your project, they will probably be transitively upgraded to the version used by this library, so beware.
Library version | Kotlin version | Ktor version | KotlinX Serialization version |
---|---|---|---|
2.4.x | 1.8.22 | 2.3.5 | 1.5.1 |
2.3.x | 1.8.21 | 2.3.0 | 1.5.0 |
2.2.x | 1.8.20 | 2.3.0 | 1.5.0 |
2.1.x | 1.7.10 | 2.0.3 | 1.3.3 |
2.0.x | 1.7.10 | 2.0.3 | 1.3.3 |
1.2.x | 1.7.10 | 2.0.3 | - |
1.1.x | 1.5.31 | 1.6.4 | - |
1.0.x | 1.4.21 | 1.4.3 | - |
Snapshots of the current in-development release are also published to Maven Central. You can use them in your project as well, but are likely to be unstable. You can find more information on the Wiki.
Feedback on the library is always welcomed and appreciated! Whether it's bug reports, suggestions, or even just questions, please let me know by creating an issue or discussion on this GitHub repository.