aon4o / cs2-gsi-parser
A parser for CS2 Game State Integration data.
Fund package maintenance!
aon4o
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/aon4o/cs2-gsi-parser
Requires
- php: ^8.4
- psy/psysh: ^0.12.12
Requires (Dev)
- laravel/pint: ^1.25
- pestphp/pest: ^4.1
- pestphp/pest-plugin-type-coverage: ^4.0
- rector/rector: ^2.2
README
This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require aon4o/cs2-gsi-parser
Usage
Parser
The GameState::from() function accepts a JSON string, an associative array or an object.
The result you get back is a fully typed object representing the game state.
use Aon4o\Cs2GsiParser\GameState; /** @var string|array|object $data */ $game_state = GameState::from($data); echo $game_state->map->name; // de_dust2
Config generator
You can also generate a config file for CS2 GSI.
use Aon4o\Cs2GsiParser\ConfigWriter; $config = ConfigWriter::new() ->setUrl('http://yourdomain.com/cs2-gsi-endpoint') ->setAuthToken('your_auth_key') ->setSettings(timeout: 5.0, buffer: 0.1, throttle: 0.1, heartbeat: 30.0) ->get(); echo $config; // "cs2-gsi" // { // "uri" "http://yourdomain.com/cs2-gsi-endpoint" // "timeout" "5" // "buffer" "0.1" // "throttle" "0.1" // "heartbeat" "30" // "auth" // { // "token" "your_auth_key" // } // "data" // { // "map_round_wins" "1" // "map" "1" // "player_id" "1" // "player_match_stats" "1" // "player_state" "1" // "player_weapons" "1" // "provider" "1" // "round" "1" // "allgrenades" "1" // "allplayers_id" "1" // "allplayers_match_stats" "1" // "allplayers_position" "1" // "allplayers_state" "1" // "allplayers_weapons" "1" // "bomb" "1" // "phase_countdowns" "1" // "player_position" "1" // } // }
Event Extractor
The package also provides a custom event extractor.
This is not a feature of CS2 GSI, but a custom definition of events based on changes in the game state.
The events are defined in the Aon4o\Cs2GsiParser\Enums\Custom\Event
enum.
use Aon4o\Cs2GsiParser\GameState; use Aon4o\Cs2GsiParser\EventExtractor; /** @var GameState $prev */ /** @var GameState $curr */ new EventExtractor($prev, $curr)->allEvents(); new EventExtractor($prev, $curr)->mapEvents(); new EventExtractor($prev, $curr)->playerEvents(); new EventExtractor($prev, $curr)->roundEvents(); // Example output array:1 [ 0 => Aon4o\Cs2GsiParser\Enums\Custom\Event {#741 +name: "MAP_PHASE_CHANGED" +value: "map.phase_changed" } ]
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.