skadistats / clarity-examples

Example code for clarity
BSD 3-Clause "New" or "Revised" License
113 stars 37 forks source link

Reading the Game info #28

Closed peemoRoyal closed 8 years ago

peemoRoyal commented 8 years ago

Hey!

I want to parse out the hero names at the beginning of my parsing process to be able to map them to the CDOTA_DataRadiant/Dire. They are in the PlayerRessources, but on the EntityCreated they are not yet initialized, so i was thinking why not use the Demoinfo, which looks like this:

playback_time: 4133.167 playback_ticks: 123995 playback_frames: 61997 game_info { dota { match_id: 2275953964 game_mode: 1 game_winner: 3 player_info { hero_name: "npc_dota_hero_magnataur" player_name: "Js7" is_fake_client: false steamid: 76561198278114357 game_team: 2 } player_info { hero_name: "npc_dota_hero_lina" player_name: "Survarium" is_fake_client: false steamid: 76561198284699594 game_team: 2 } ...

it seems to be kind of JSON but isnt. Is it just a string fromatted this way? I just want to read out several values like player_info->hero_name. Problem is i could not find anything which allows me to do that, and parsing the String one by one seems a bit too much. Does something like info.getKey("hero_name) exist and am I just to stupid to find it?

Kind regards and thx in advance Peter

spheenik commented 8 years ago

It's not JSON, it's a protobuf message. An example to iterate over the players and find hero names is this:

import skadistats.clarity.Clarity;
import skadistats.clarity.wire.common.proto.Demo;
import skadistats.clarity.wire.common.proto.Demo.CDemoFileInfo;

public class Main {
    public static void main(String[] args) throws Exception {
        CDemoFileInfo info = Clarity.infoForFile(args[0]);
        for (Demo.CGameInfo.CDotaGameInfo.CPlayerInfo playerInfo : info.getGameInfo().getDota().getPlayerInfoList()) {
            System.out.println(playerInfo.getHeroName());
        }
    }
}
Leyota commented 8 years ago

Hello. Can you help with some info please. How can I get ability learning info (time, level, hero)?

spheenik commented 8 years ago

Hey Leyota, please do not append your question to an unrelated thread. Thank you! Regarding your question, may I refer you to the implementation yasp uses to extract data? If you have more questions, please open a new issue. :)