Results 1 to 10 of 35

Thread: CMsgBotWorldState, Protobufs, and You

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Basic Member
    Join Date
    Dec 2016
    Posts
    731

    CMsgBotWorldState, Protobufs, and You

    So I started playing around today with the capability to dump world state to a specific port through a serialized TCP connection in protobuf format.

    Go into your Steam Library, right click on Dota 2 -> Properties, click on SET LAUNCH OPTIONS, and make sure you have specified:
    Code:
    -novid -console -condebug -botworldstatetosocket_dire 12121 -botworldstatetosocket_frames 15
    The 12121 specifies the port (for DIRE side), you can change if you wish (to a different PORT or to modify for RADIANT), the 15 specifies every how many frames the data is updated, you can change to your desire. The other things are optional, but you probably want them.

    Example code to retrieve this information from a running bot game (will only pull one world state protobuf frame and then exit):
    Code:
    import socket
    from struct import *
    
    HOST = '127.0.0.1'  # The remote host
    PORT = 12121        # The same port as used by the server
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.connect((HOST, PORT))
    
        f = open('tmp.bin', 'bw')
    
        i=0
        while i < 1:
            binSize = s.recv(4)
            print(binSize)
    
            if binSize:
                protoSize = unpack("<I", binSize)
                print("protoSize: %d" % (protoSize[0]))
    
                binData = s.recv(protoSize[0])
                f.write(binData)
                i += 1
    
        print("Closing Socket")
    
        f.close()
        s.close()
    Example code to load the stored protobuf frame:
    You will need the protobuf mapped python file attached (will need to be updated if the .proto changes). You can auto-generate this file yourself using the protobuf compiler (known as: "protoc") available from Google. I attached the generated result below in case you don't know what to do or are lazy. Just change the extension of the file from .py.txt to .py before using.
    CMsgBotWorldState_pb2.py.txt UPDATED: 09/20/2017 - 9:52pm EDT

    Code:
    import CMsgBotWorldState_pb2 as pb
    f = open('tmp.bin', 'rb')
    worldState = pb.CMsgBotWorldState()
    worldState.ParseFromString(f.read())
    f.close()
    print(worldState)
    CURRENT ISSUES:
    1) Game crashes when socket connection is closed after an initial connect

    2) FIXED - last_hit and gold values are confused - apparently there was an updated protobuf structure and I wasn't using it (added reliable and unreliable gold)

    3) All handle and caster_handle values seem to be 0... this seems to be a bug

    SUGGESTIONS:
    * Add an ENUM for TEAM_ID to .proto
    * Add an ENUM for PRIMARY_ATTRIBUTE to .proto
    * Add an ENUM for RUNE_TYPE to .proto
    * Add an ENUM for RUNE_STATUS to .proto
    * Add an ENUM for ACTION_TYPE to .proto (of Bots)
    * Add ability_name to Ability proto (affects Items too)
    * Add physical_resist to Unit proto (we have armor and magic_resist currently... not sure if armor is currently valuable information or not)
    * Add "optional CourierState courier_state = 141;" to .proto and add an ENUM for CourierState
    * Add an ENUM for game_state to .proto
    * Add an ENUM for hero_pick_state to .proto
    * Add net worth information to players

    DREAM SUGGESTIONS:
    * Make this possible during watching replay matches
    * Valve maintained repository of pre-dumped world state serialized proto files from all tournaments

    QUESTIONS:
    1) game_time is what? RealTime(), GameTime() or DotaTime()?
    Answer: as of the new protobuf structure there is now a game_time and a dota_time they correspond to the API of GameTime() and DotaTime() respectively.

    2) Depending on answer to #1, what happens during a Pause?
    Answer: we keep getting new protobuf structure every N frames (as specified by our launch options) but we can use dota_time to detect no time has passed and there we are paused.
    Last edited by nostrademous; 09-21-2017 at 06:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •